﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EventMgrLib;

namespace SmartMotion.Core
{
    public class Flow
    {
        private EventMgr _em;
        public Flow()
        {
            _em=EventMgr.Ins;
            Nodes = new ActionItemConnection();
        }
        public string Group { get; set; }

        [Browsable(false)]
        public string Name { get; set; }

        public ActionItemConnection  Nodes { get; set; }

        public void Run()
        {
            _em.GetEvent<DebugMessage>().Publish($"流程[{Name}]开始执行");
            foreach (ActionItem actionItem in Nodes)
            {
                actionItem.Run();
            }
            _em.GetEvent<DebugMessage>().Publish($"流程[{Name}]执行完成");
        }
    }   

    public class ActionItemConnection : CollectionBase
    {
        public ActionItemConnection()
        {
            
        }

        public int Add(ActionItem node)
        {
            return this.InnerList.Add(node);
        }

        public ActionItem this[int index]
        {
            get
            {
                return this.InnerList[index] as ActionItem;
                
            }
        }

        public void Remove(ActionItem node)
        {
            this.InnerList.Remove(node);
        }
    }
}   
